package com.ly.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ly.entity.TeamType;
import com.ly.mapper.TeamMapper;
import com.ly.mapper.TeamTypeMapper;
import com.ly.pojo.dto.TeamTypeDTO;
import com.ly.service.TeamTypeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author : 黑渊白花
 * @ClassName TeamTypeServiceImpl
 * @date : 2025/2/8 22:31
 * @Description
 */
@Service
@Slf4j
public class TeamTypeServiceImpl extends ServiceImpl<TeamTypeMapper, TeamType> implements TeamTypeService {
    @Autowired
    private TeamTypeMapper teamTypeMapper;

    @Autowired
    private TeamMapper teamMapper;


    @Override
    public IPage<TeamType> getPage(TeamTypeDTO teamTypeDTO) {
        LambdaQueryWrapper<TeamType> lqw = new LambdaQueryWrapper<>();
        lqw.like(Strings.isNotEmpty(teamTypeDTO.getName()),TeamType::getName,teamTypeDTO.getName());
        IPage page = new Page(teamTypeDTO.getPageNum(),teamTypeDTO.getPageSize());
        teamTypeMapper.selectPage(page,lqw);
        return page;
    }

    @Override
    public Boolean delete(Integer id) {
        QueryWrapper qw=new QueryWrapper();
        qw.eq("type_id",id);
        Long count = teamMapper.selectCount(qw);
        if(count>0){
            return false;
        }else {
            teamTypeMapper.deleteById(id);
            return true;
        }
    }

    @Override
    public List<Map<String, Object>> getClubTypeCounts() {
        List<Map<String, Object>> clubTypeCounts = teamTypeMapper.getClubTypeCounts();
        return clubTypeCounts;
    }

}
